clear all;
close all;
load('Img10by6.mat');
n_set = 60;
time=zeros(n_set,6);
Res=zeros(n_set,6);
GroundTruth=ones(n_set,1)*(1:6);
img_idx=1;


for set=1:1:n_set
    for i=1:1:6
        if (i==3)
            figure(1);Legend('N<=3, Subitizing works!');
        else
            figure(1);Legend('N>3, Subitizing fails and Counting starts');
        end
        img_idx=i
        input=Img(:,:,img_idx);
%         subplot(n_set,6,img_idx);imagesc(input);
        if (1)
%             most current normal subject model
              [Res(set,i) time(set,i)] = f_run20110928b_mixed_sub3items_1fig(input, 'fig_off', 'mixed', .6, .05, .05);
%          [Res(set,i) time(set,i)]=f_run20110402_mixed_sub3items_1fig(input, 'fig_off');
%             [Res(set,i) time(set,i)]=f_run0923_noLIP(input, 'fig_off', '');
%             most current LIP lesion model
            %[Res(set,i) time(set,i)]=f_run20110409_noLIP(input,'fig_off', 'mixed');

            %[Res(set,i) time(set,i)]=f_run20110330_mixed_sub3items_1fig(input, 'fig_off');
            %[Res(set,i) time(set,i)]=f_run0715_mixed_sub3items_b(input, 'fig_off');
            %[Res(set,i) time(set,i)]=f_run0923_noLIP(input, 'fig_off', 'mixed');
        else
            %[N(i) time(i)]=f_run0923_noLIP(input, 'fig_off', 'mixed');
        end
        img_idx=img_idx+1;
    end
end
%load('LefData');
%Data=LefData
%  load('SubjectData');
%  Data=SubjectData;
 load('SubjectData_unlimited');
 Data=SubjectData_unlimited;
x=1:6;
avg_res = mean(Res,1);
error=std(Res,1);

% compute mean absolute error
AvgResAugmented=ones(n_set,1)*avg_res;
MeanAbsError=mean(abs(Res-AvgResAugmented),1);

avg_time = 30*mean(time,1);  %Avg and rescale by factor 3
figure('Color',[1 1 1]); xlabel('Average Prediction');
plot(x,x, 'LineWidth', 1,'color', 'k', 'LineStyle', '--');hold on;
plot(x, Data(3,:),'LineWidth',2);hold on;
errorbar(x,avg_res,error,'LineWidth',2,'Color','g');title('Average Prediction');
legend('Perfect Prediction', 'Subject Data', 'Model Prediction');
figure( 'color',[1 1 1]); h=plot(x, Data(2,:),x,avg_time,'LineWidth',2);title('Average Response Time');legend('Subject Data', 'Model Prediction');

%compute precision
Diff=(GroundTruth-Res);
AbsNormDiff=abs(Diff/(max(max(Diff))));
BitError=ceil(AbsNormDiff);
ErrorRate=sum(BitError,1)/n_set;
figure('color',[1 1 1]); plot(x, Data(1,:),x,ErrorRate, 'LineWidth',2);title('Error Rate');
figure('color',[1 1 1]); plot(x, Data(4,:),x,MeanAbsError, 'LineWidth',2);title('Error');